package fanshi;

public class jihe<T> {
   private T[] arr;
   private int size;

    public jihe(int size) {
        this.size = size;
        arr=(T[]) new Object[size];
    }

    public void set(int index,T val) {
        arr[index]=val;
    }

    public T get(int index){

        return arr[index];
    }

    public void show(){
        for (T e:arr){
            System.out.println(e);
        }
        System.out.println();
    }
    public int length(){
        return size;
    }
    public static void main(String[] agrs){
        jihe<Integer> jh=new jihe<>(5);
        jh.set(2,35);
        jh.set(0,45);
        jh.show();
        jh.out(jh);
        System.out.println(jh.get(2));
        jihe<Student> jh2=new jihe<>(5);
        Student s1=new Student("孙悟空",500);
        Student s2=new Student("猪八戒",400);
        Student s3=new Student("唐僧",300);
        jh2.set(0,s1);
        jh2.set(1,s2);
        jh2.set(2,s3);
        jh2.show();
        //jh2.out(); 出错，由于out函数定义的时Number型的与jh2的Student类型不相通
    }
    public static void out(jihe<? extends Number>jh){
        for(int i=0;i<jh.length();i++){
            System.out.println(jh.get(i));
        }
        System.out.println();

    }
}
